package com.td.module.pests.dal.mysql.library;

import com.td.framework.common.pojo.PageResult;
import com.td.framework.mybatis.core.mapper.BaseMapperX;
import com.td.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.td.module.pests.controller.admin.library.vo.LibraryExportReqVO;
import com.td.module.pests.controller.admin.library.vo.LibraryPageReqVO;
import com.td.module.pests.dal.dataobject.library.LibraryDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 病虫害知识库 Mapper
 *
 * @author wangxx
 */
@Mapper
public interface LibraryMapper extends BaseMapperX<LibraryDO> {

    default PageResult<LibraryDO> selectPage(LibraryPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<LibraryDO>()
                .likeIfPresent(LibraryDO::getDiseaseName, reqVO.getDiseaseName())
                .eqIfPresent(LibraryDO::getDiseaseType, reqVO.getDiseaseType())
                .eqIfPresent(LibraryDO::getCropsType, reqVO.getCropsType())
                .likeIfPresent(LibraryDO::getCrop, reqVO.getCrop())
                .eqIfPresent(LibraryDO::getDiseaseNameOther, reqVO.getDiseaseNameOther())
                .eqIfPresent(LibraryDO::getDiseaseNameEng, reqVO.getDiseaseNameEng())
                .eqIfPresent(LibraryDO::getDiseaseIntro, reqVO.getDiseaseIntro())
                .eqIfPresent(LibraryDO::getDiseaseImgList, reqVO.getDiseaseImgList())
                .eqIfPresent(LibraryDO::getCMethod, reqVO.getCMethod())
                .eqIfPresent(LibraryDO::getDamageSym, reqVO.getDamageSym())
                .eqIfPresent(LibraryDO::getHabits, reqVO.getHabits())
                .eqIfPresent(LibraryDO::getMorphology, reqVO.getMorphology())
                .betweenIfPresent(LibraryDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(LibraryDO::getId));
    }

    default List<LibraryDO> selectList(LibraryExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<LibraryDO>()
                .likeIfPresent(LibraryDO::getDiseaseName, reqVO.getDiseaseName())
                .eqIfPresent(LibraryDO::getDiseaseType, reqVO.getDiseaseType())
                .eqIfPresent(LibraryDO::getCropsType, reqVO.getCropsType())
                .likeIfPresent(LibraryDO::getCrop, reqVO.getCrop())
                .eqIfPresent(LibraryDO::getDiseaseNameOther, reqVO.getDiseaseNameOther())
                .eqIfPresent(LibraryDO::getDiseaseNameEng, reqVO.getDiseaseNameEng())
                .eqIfPresent(LibraryDO::getDiseaseIntro, reqVO.getDiseaseIntro())
                .eqIfPresent(LibraryDO::getDiseaseImgList, reqVO.getDiseaseImgList())
                .eqIfPresent(LibraryDO::getCMethod, reqVO.getCMethod())
                .eqIfPresent(LibraryDO::getDamageSym, reqVO.getDamageSym())
                .eqIfPresent(LibraryDO::getHabits, reqVO.getHabits())
                .eqIfPresent(LibraryDO::getMorphology, reqVO.getMorphology())
                .betweenIfPresent(LibraryDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(LibraryDO::getId));
    }

}
